package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.AnswerBean;

import java.util.List;

/**
 * Created by songedwin on 2017/10/31.
 */

public class AnswerAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public AnswerAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.answer_cardview, parent, false);
        return new AnswerAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final AnswerBean entity = (AnswerBean) mDataList.get(position);
        if (null == entity)
            return;
        AnswerAdapter.ViewHolder viewHolder = (AnswerAdapter.ViewHolder) holder;
        viewHolder.answer_username.setText(entity.getUser_name().toString()+":");
        viewHolder.answer_qustion.setText(entity.getAsk().toString());

        if (entity.getAnswer()!=null)
        {
            viewHolder.answer_answer.setText(entity.getAnswer().toString());
        }else
        {
            viewHolder.answer_answer.setText("大师还未作出回答。");
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView answer_username,answer_qustion,answer_answer;
        public ViewHolder(View itemView) {
            super(itemView);
            answer_username=(TextView) itemView.findViewById(R.id.answer_username);
            answer_qustion=(TextView) itemView.findViewById(R.id.answer_qustion);
            answer_answer=(TextView) itemView.findViewById(R.id.answer_answer);
        }
    }
}
